/*
	File:				Ability.cpp
	Course:		SGP 1208
	Author:		Kori Po
	Purpose:	Ability object class
*/

#include "Ability.h"
#include "Game.h"
#include "Messages\DestroyAbilityMessage.h"

#include "../SGD Wrappers/CSGD_TextureManager.h"
#include "../SGD Wrappers/CSGD_XAudio2.h"
#include "../SGD Wrappers/SGD_Math.h"

#include "EventSystem.h"

#include "GameplayState.h"


CAbility::CAbility(void)
{
	CEntity::m_nType		= OBJ_ABILITY;

	m_strName						= "NO NAME!";
	m_nManaCost				= 5;
	m_nPlayerMovement	= 0;
	m_nTargetMovement = 0;
	m_nDamage					= 25;
	m_nHeal							= 0;
	m_nBuff								= 0;
	m_nNerf							= 0;
	m_nApplication				=	BURST;
	m_nAoE							= SINGLE;

	SetWidth(8);
	SetHeight(8);

	m_TextureGuy			= CSGD_TextureManager::GetInstance();
	m_Messenger				= CMessageSystem::GetInstance();
	m_AudioGuy				= CSGD_XAudio2::GetInstance();
	m_pOwner					= nullptr;

	Hadouken = new CSpriteAnimatorFireball();
	Hadouken->Play(true,1);

	m_bFirst = true;

	// Temp
	m_nAbilityIconID		= m_TextureGuy->LoadTexture(_T("Resource/Graphics/Shot.png"), D3DCOLOR_XRGB(255,255,255));
}

CAbility::~CAbility(void)
{

}

void CAbility::Update(float fElapsedTime)
{
	CGame* pGame = CGame::GetInstance();

	RECT rScreen	= { 0, 0, pGame->GetScreenWidth(), pGame->GetScreenHeight() };
	RECT rSelf		= GetRect();
	RECT rOverlap	= { };

	if( IntersectRect( &rOverlap, &rSelf, &rScreen ) == FALSE )
	{
		// Self-destruct
		CDestroyAbilityMessage* pMsg_EX1 = new CDestroyAbilityMessage (this);
		m_Messenger->SendMsg( pMsg_EX1 );
		pMsg_EX1 = nullptr;
	}

	Hadouken->Update(fElapsedTime);

	CEntity::Update(fElapsedTime);
}

void CAbility::Render(void)
{
	float ToDrawX = int(GetX()) - float(GetWidth()/2);
	float ToDrawY = int(GetY()) - float(GetHeight()/2);

	int ToDrawABX = 5 + 76;
	int ToDrawABY = 5 + 52;
	
	//int ToDrawABXX = 5 + 152;
	//int ToDrawABYY = 5 + 52;

	Hadouken->Render((float)CEntity::GetX(), (float)CEntity::GetY(), 1, GetRotation(), D3DCOLOR_XRGB(255,255,255));

	m_TextureGuy->Draw(m_nAbilityIconID, ToDrawABX, ToDrawABY);

}

void CAbility::Trigger(void)
{

}